/**
 * FormRelForn.java
 * Copyright (C) 2009 Jose Mauro da Silva Sandy
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * FormRelForn.java
 *
 * Created on 28/06/2009, 21:56:32
 */

package frames;

import java.sql.ResultSet;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import javax.swing.JOptionPane;
import negocio.pessoas.Fornecedor;
import negocio.produto.Grupo;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import plagio.postgres.ConnectionPostgres;
import utils.*;

/**
 *
 * @author jmsandy
 */
public class FormRelForn extends javax.swing.JDialog {

    //<editor-fold defaultstate="collapsed" desc="Fields">
    ConnectionPostgres conn       = new ConnectionPostgres();
    SimpleDateFormat sdf          = new SimpleDateFormat("dd/MM/yyyy");
    private Grupo grupo           = null;
    private Fornecedor fornecedor = null;
    Date dtInicial                = null;
    Date dtFinal                  = null;
    Integer situacao              = null;
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Constructor">
    /** Creates new form FormRelForn */
    public FormRelForn() {
        initComponents();
        initializeMyComponentes();
    }
    //</editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormRelForn().setVisible(true);
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        textDtInicial = new javax.swing.JFormattedTextField();
        lbDataInicio = new javax.swing.JLabel();
        lbIntervalo = new javax.swing.JLabel();
        textDtFinal = new javax.swing.JFormattedTextField();
        lbFornecedor = new javax.swing.JLabel();
        textGrupo = new javax.swing.JTextField();
        btnGrupo = new javax.swing.JButton();
        lbGrupo = new javax.swing.JLabel();
        textFornecedor = new javax.swing.JTextField();
        btnFornecedor = new javax.swing.JButton();
        lbProduto = new javax.swing.JLabel();
        textDescricao = new javax.swing.JTextField();
        panelBotao = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        btnVisualizar = new javax.swing.JButton();

        setTitle("Filtro - Compras por Fornecedor");
        setName("formRelForn"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Filtro", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("SansSerif", 0, 12))); // NOI18N

        textDtInicial.setBackground(java.awt.Color.white);
        try {
            textDtInicial.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        textDtInicial.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        textDtInicial.setFocusLostBehavior(javax.swing.JFormattedTextField.COMMIT);
        textDtInicial.setFont(new java.awt.Font("SansSerif", 0, 12));
        textDtInicial.setPreferredSize(new java.awt.Dimension(54, 26));

        lbDataInicio.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbDataInicio.setText("Data de Início");

        lbIntervalo.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbIntervalo.setText("à");

        textDtFinal.setBackground(java.awt.Color.white);
        try {
            textDtFinal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        textDtFinal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        textDtFinal.setFocusLostBehavior(javax.swing.JFormattedTextField.COMMIT);
        textDtFinal.setFont(new java.awt.Font("SansSerif", 0, 12));
        textDtFinal.setPreferredSize(new java.awt.Dimension(54, 26));

        lbFornecedor.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbFornecedor.setText("Fornecedor");

        textGrupo.setBackground(java.awt.Color.white);
        textGrupo.setEditable(false);
        textGrupo.setFont(new java.awt.Font("SansSerif", 0, 12));
        textGrupo.setDisabledTextColor(java.awt.Color.white);
        textGrupo.setPreferredSize(new java.awt.Dimension(10, 26));

        btnGrupo.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnGrupo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/open.png"))); // NOI18N
        btnGrupo.setBorderPainted(false);
        btnGrupo.setContentAreaFilled(false);
        btnGrupo.setMaximumSize(new java.awt.Dimension(28, 28));
        btnGrupo.setMinimumSize(new java.awt.Dimension(28, 28));
        btnGrupo.setPreferredSize(new java.awt.Dimension(28, 28));
        btnGrupo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnGrupoMouseClicked(evt);
            }
        });

        lbGrupo.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbGrupo.setText("Grupo");

        textFornecedor.setBackground(java.awt.Color.white);
        textFornecedor.setEditable(false);
        textFornecedor.setFont(new java.awt.Font("SansSerif", 0, 12));
        textFornecedor.setDisabledTextColor(java.awt.Color.white);
        textFornecedor.setPreferredSize(new java.awt.Dimension(10, 26));

        btnFornecedor.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnFornecedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/open.png"))); // NOI18N
        btnFornecedor.setBorderPainted(false);
        btnFornecedor.setContentAreaFilled(false);
        btnFornecedor.setMaximumSize(new java.awt.Dimension(28, 28));
        btnFornecedor.setMinimumSize(new java.awt.Dimension(28, 28));
        btnFornecedor.setPreferredSize(new java.awt.Dimension(28, 28));
        btnFornecedor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnFornecedorMouseClicked(evt);
            }
        });

        lbProduto.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbProduto.setText("Desc. Produto");

        textDescricao.setBackground(java.awt.Color.white);
        textDescricao.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        textDescricao.setToolTipText("");
        textDescricao.setMaximumSize(new java.awt.Dimension(40, 40));
        textDescricao.setPreferredSize(new java.awt.Dimension(100, 26));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbDataInicio)
                            .addComponent(lbFornecedor))
                        .addGap(14, 14, 14)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(textDtInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4)
                                .addComponent(lbIntervalo)
                                .addGap(3, 3, 3)
                                .addComponent(textDtFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(textFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbGrupo)
                            .addComponent(lbProduto))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(textGrupo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(textDescricao, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE))))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnFornecedor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnFornecedor, btnGrupo});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbDataInicio)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(textDtFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(textDtInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(5, 5, 5)
                            .addComponent(lbIntervalo))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(lbFornecedor))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnFornecedor, 0, 0, Short.MAX_VALUE)
                            .addComponent(textFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lbGrupo)
                                    .addComponent(textGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lbProduto)
                                    .addComponent(textDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(btnGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnFornecedor, btnGrupo, textDtFinal, textDtInicial, textFornecedor, textGrupo});

        panelBotao.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, java.awt.Color.gray));
        panelBotao.setFont(new java.awt.Font("DejaVu Sans", 0, 12));

        btnCancelar.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setToolTipText("Cancelar");
        btnCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCancelarMouseClicked(evt);
            }
        });

        btnVisualizar.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnVisualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/print.png"))); // NOI18N
        btnVisualizar.setText("Visualizar");
        btnVisualizar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnVisualizarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout panelBotaoLayout = new javax.swing.GroupLayout(panelBotao);
        panelBotao.setLayout(panelBotaoLayout);
        panelBotaoLayout.setHorizontalGroup(
            panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotaoLayout.createSequentialGroup()
                .addContainerGap(117, Short.MAX_VALUE)
                .addComponent(btnVisualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(116, 116, 116))
        );
        panelBotaoLayout.setVerticalGroup(
            panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnVisualizar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelBotao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-517)/2, (screenSize.height-276)/2, 517, 276);
    }// </editor-fold>//GEN-END:initComponents

    //<editor-fold defaultstate="collapsed" desc="Events">
    private void btnCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelarMouseClicked
        this.dispose();
}//GEN-LAST:event_btnCancelarMouseClicked

    private void btnVisualizarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnVisualizarMouseClicked

        try{
            // Verifica se a busca pode ser realizada
            if(validSearch()){
                if(fornecedor == null){
                    fornecedor = new Fornecedor();
                }

                // Recupera os fornecedores que satisfacam os filtros
                ResultSet rs = fornecedor.recLstFornRel(textFornecedor.getText());
                JRDataSource jrds = new JRResultSetDataSource(rs);
                this.setVisible(false);

                // Cria os parametros para ser passado
                JasperPrint jp = GeradorRelatorio.generateReport(
                        "relComFor.jasper", mountParameter(), jrds);

                JasperViewer.viewReport(jp, false);

            } else{
                JOptionPane.showMessageDialog(this, "Datas incompativeis.");
            }
        }
        catch(Exception ex){}
}//GEN-LAST:event_btnVisualizarMouseClicked

    // Realiza a busca do grupo
    private void btnGrupoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnGrupoMouseClicked
        if(btnGrupo.isEnabled()){
            FormGrupo form = new FormGrupo(FormGrupo.K_FORM_PESQUISA);
            form.setModal(true);
            form.setVisible(true);

            this.grupo = new Grupo();
            this.grupo = form.getGrupo();
            form.dispose();

            this.textGrupo.setText(
                    this.grupo != null ? this.grupo.getNome() : "");
        }
}//GEN-LAST:event_btnGrupoMouseClicked

    // Realiza a busca do fornecedor
    private void btnFornecedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFornecedorMouseClicked
        if(btnFornecedor.isEnabled()){
            FormFornecedor form =
                            new FormFornecedor(FormFornecedor.K_FORM_PESQUISA);
            form.setModal(true);
            form.setVisible(true);

            this.fornecedor = new Fornecedor();
            this.fornecedor = form.getFornecedor();
            form.dispose();

            this.textFornecedor.setText(
                    this.fornecedor != null ? this.fornecedor.getNome() : "");
        }
}//GEN-LAST:event_btnFornecedorMouseClicked

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
       if(conn != null)
        conn.closeConnection();

       dispose();
    }//GEN-LAST:event_formWindowClosed
    //</editor-fold>

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnFornecedor;
    private javax.swing.JButton btnGrupo;
    private javax.swing.JButton btnVisualizar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbDataInicio;
    private javax.swing.JLabel lbFornecedor;
    private javax.swing.JLabel lbGrupo;
    private javax.swing.JLabel lbIntervalo;
    private javax.swing.JLabel lbProduto;
    private javax.swing.JPanel panelBotao;
    private javax.swing.JTextField textDescricao;
    private javax.swing.JFormattedTextField textDtFinal;
    private javax.swing.JFormattedTextField textDtInicial;
    private javax.swing.JTextField textFornecedor;
    private javax.swing.JTextField textGrupo;
    // End of variables declaration//GEN-END:variables

    //<editor-fold defaultstate="collapsed" desc="Methods">
    private void initializeMyComponentes(){
        initializeFields();
    }

    // Inicializa os campos com o valores padroes
    private void initializeFields(){
        textDtFinal.setText(null);
        textDtInicial.setText(null);
        textGrupo.setText("");
        textFornecedor.setText("");
        textDescricao.setText("");
    }

    // Valida os campos para busca
    private Boolean validSearch(){
        Boolean valid = true;
        try{
            dtInicial = textDtInicial.getText().equals("  /  /    ") ?
                null : new Date( sdf.parse(textDtInicial.getText()).getTime());

            dtFinal = textDtFinal.getText().equals("  /  /    ") ?
                null : new Date( sdf.parse(textDtFinal.getText()).getTime());

            valid = (dtInicial != null && dtFinal == null) ? false : true;

            if(valid && dtInicial != null && dtFinal != null){
                valid = dtFinal.getTime() >= dtInicial.getTime() ? true : false;
            }
        }
        catch(ParseException ex){
            ex.printStackTrace();
            valid = false;
        }
        return valid;
    }

    // Monta a lista de parametros para busca
    private HashMap mountParameter() {
        HashMap parameter = new HashMap();
        // Pega a conexao para fornecer ao relatorio

        try{

            conn = ConnectionSystem.connectionSystem();

            parameter.put("REPORT_CONNECTION", conn.getConnection());
            parameter.put("PRODUTO",
                            textDescricao.getText().toUpperCase().trim() + "%");
            parameter.put("GRUPO", grupo != null ? grupo.getCod_objeto() : "%");
            parameter.put("DTINICIAL",
                    dtInicial != null ? textDtInicial.getText() : "01/01/1970");
            parameter.put("DTFINAL",
                        dtFinal != null ? textDtFinal.getText() : "31/12/2100");
        }
        catch(Exception ex){}
        return parameter;
    }
    //</editor-fold>
}
